package 可变参数;

public class ArgsDemo01 {
    public static void main(String[] args) {
        System.out.println(sum(10, 20));
        System.out.println(sum(10,20,30));
        System.out.println(sum(10,20,30,40));

        System.out.println(sum(10,20,30,40,50));
        System.out.println(sum(10,20,30,40,50,60));
        System.out.println(sum(10,20,30,40,50,60,70));

    }
    public static int sum(int...a){//可变参数:a是一个数组，他将方法调用的参数封装到a中；
//        public static int sum(int b,int...a){出现多个参数包含可变参数的情况下，可变参数放最后
//        return 0;
        int sum=0;

        for(int i:a){
            sum+=i;
        }
        return  sum;
    }


//        public static int sum ( int a, int b){
//            return a + b;
//        }
//        public static int sum ( int a, int b, int c){
//            return a + b + c;
//        }
//        public static int sum ( int a, int b, int c, int d) {
//            return a+b+c+d;
//        }

}
